// Task 函子
import fs from "fs";
import task from "folktale/concurrency/task/index.js";
import fp from "lodash/fp.js";

function readFile(filename) {
  return task.task((resolver) => {
    fs.readFile(filename, "utf-8", (err, data) => {
      if (err) {
        resolver.reject(err);
      }
      resolver.resolve(data);
    });
  });
}

readFile("package.json")
  .map(fp.split("\n"))
  .map(fp.find((x) => x.includes("version")))
  .run()
  .listen({
    onRejected: (err) => {
      console.log(err);
    },
    onResolved: (value) => {
      console.log(value);
    },
  });
